<template>
  <a-card>
    <a-row>
      <searchData :searchData="searchArr" @search="search"></searchData>
      <a-button type="primary" @click="addAdjust">
        新增调整
      </a-button>
    </a-row>
    <a-row :gutter="10" class="page-height">
      <a-col :span="4" style="border-right: 1px solid #d9d9d9" class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }">
        <a-card :bordered="false" class="page-height-tree">
          <!-- 公司组织树搜索 -->
          <PermissionTreeOrganization :collapsed.sync="collapsed" @select="handleSelect" :isCostTree="true"/>
        </a-card>
      </a-col>
      <a-col :span="20" class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''">
        <list-table ref="table" :columns="columns" :startIndex="1" :request="loadData"
          :page-keys="['pageNum', 'pageSize', 'total']">
          <span slot="operation" slot-scope="text, record">
            <MoreButton>
              <!-- <MoreButton> -->
              <a v-btnPermission="'bm_047_loo_06'" @click="handleManage(record, 0)">查看</a>
              <!-- 编辑 -->
              <span v-if="record.status == 0 || record.status == 3">
                <a v-btnPermission="'bm_047_edi_07'" @click="handleManage(record, 2)">编辑</a>
              </span>
              <template v-if="record.status != '0' && record.process == 0">
                 <a v-btnPermission="'pm_067_loo_01'" 
                  @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批信息</a>
                 </template>
            </MoreButton>
          </span>

          <span slot="status" slot-scope="text, record">
            <list-status :status="record.status" :isApproval="true" conversion="en" :text="text"></list-status>
          </span>
        </list-table>
      </a-col>
    </a-row>
  </a-card>
</template>

<script>
import BasePage from '@/views/basePage' // 基础配置
import { getPageComBusinessCostMonthly } from '@/api/businessAffairs/InformationAdjustment'
import MoreButton from '@/components/MoreButton'
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '分公司',
    dataIndex: 'branchComName',
    ellipsis: true
  },
  {
    title: '项目名称',
    dataIndex: 'projectName',
    ellipsis: true
  },
  {
    title: '调整内容',
    dataIndex: 'content',
    ellipsis: true
  },
  {
    title: '业态',
    dataIndex: 'typeName',
    ellipsis: true
  },
  {
    title: '调整提交时间',
    dataIndex: 'submitDate',
    ellipsis: true
  },
  {
    title: '提交人',
    dataIndex: 'creatorName',
    ellipsis: true
  },
  {
    title: '状态',
    dataIndex: 'statusName',
    scopedSlots: { customRender: 'submitStatusStr' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    fixed: 'right',
    width: '180px',
    scopedSlots: { customRender: 'operation' }
  }
]
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    MoreButton,
    PermissionTreeOrganization
  },
  data(){
    return {
      collapsed:false,
      columns:columns,
      searchArr: [
        {
          name: '调整内容',
          type: 'input',
          value: 'content',
          attr: {
            rangeFormat: ['startMonth', 'endMonth']
          }
        },
        {
          name: '调整提交时间',
          type: 'dateRange',
          value: 'talksDate1',
          attr: {
            rangeFormat: ['startSubmitDate', 'endSubmitDate']
          }
        },
        {
          name: '业态',
          value: 'type',
          type: 'selectMode',
          data: [
            {
              value: '1',
              label: '土建'
            },
            {
              value: '2',
              label: '安装'
            },
            {
              value: '3',
              label: '基础设施'
            },
            {
              value: '4',
              label: '水利水电与水务环保'
            },
            {
              value: '5',
              label: '装饰与城市更新'
            }
          ]
        },

        {
          name: '状态',
          value: 'status',
          type: 'selectMode',
          data: [
            {
              value: '0',
              label: '草稿'
            },
            {
              value: '1',
              label: '审批中'
            },
            {
              value: '2',
              label: '调整完成'
            },
            {
              value: '3',
              label: '审批不通过'
            }
          ]
        }
      ],
      queryParam:{},
      loadData: async (parameter) => {
        const searchQuery = {
          orgSet: [],
          projectSet: []
        }
        if (this.selectOptions?.tageCode === 'BC') {
          searchQuery.orgSet = [this.selectOptions.orgId]
          searchQuery.projectSet =this.projectIds
        }
        // 三级-项目id
        if (this.selectOptions?.tageCode === 'PD') {
          searchQuery.projectSet = [this.selectOptions.projectId]
        }
        let searchData = Object.assign(parameter, { param: { searchQuery, ...this.queryParam } })
        return getPageComBusinessCostMonthly(searchData).then((res) => {
          return res
        })
      },
      timer2:null
    }
  },
  watch: {
    //监听路由变更
    $route(newVal) {
      console.log(newVal, 'newVal');
      if(newVal.meta.title == '商务成本计划管理'){
        this.search();
      }
      
    },
  },
  methods: {
    handleSelect(node) {
      this.selectOptions = node
      if(node.tageCode === 'CO') return;
      this.projectIds = [];
      if(node.tageCode === 'BC' && node.childTree && node.childTree.length) {
        node.childTree.map(item=> {
          if(item.tageCode === 'PD') {
            this.projectIds.push(item.projectId);
          }
        })
      }
      if(node.tageCode === 'PD') {
        this.projectIds.push(node.projectId);
      }
      this.search();
    },
     //搜索
     search(value) {

      clearTimeout(this.timer1)
        this.timer1 = setTimeout(() => {
          value && (this.queryParam = value)
          this.$refs.table.refresh(true)
        },500)
      
    },
     // 操作栏
     handleManage(record,type) {
      let query={
        editModel: type
      };
      if (record && record.id) {
        query.id = record.id;
      }
      // let url = type*1==2?'updateInformation':'informationdetail';
      this.$router.push({
        name:'updateInformation',
        query
      })
    },
    addAdjust(){
      let query={
        editModel: 1
      };
      this.$router.push({
        name: 'updateInformation',
        query
      })
    },
  }
}
</script>

<style>

</style>